
#ifndef DRAWSTRIPESHAPEHANDLER_H
#define DRAWSTRIPESHAPEHANDLER_H

#include <BImage>
#include <BPicker>
#include <BHandler>

#include "../Target.h"
#include "../LineStripe.h"
#include "../EdgeTools.h"
#include "PrimitiveTransformer.h"
#include "DrawLineStripeNote.h"

class DrawLineStripeHandler : public BHandler
{
public:
	DrawLineStripeHandler(BHandler* parent = 0);
	~DrawLineStripeHandler();

	void changeOperaMode();
	void revertPoints();
	void applyChanges();
	void resetChanges();

protected:
	bool collectEdges(const BVectorArray* vertices, const BElement* element, int index, EdgeArray& edges);

protected:
	void slotAssetChanged(BObject* object, const BValue& value);
	void slotPropertyChanged(BObject* object, const BValue& value);
	void slotModeChanged(BObject* object, const BValue& value);
	void slotTransformFinished(BObject* object, const BValue& value);

protected:
	virtual void attached(BViewer* viewer);
	virtual void detached(BViewer* viewer);

	virtual void paint(BPainter& painter);
	virtual void render(BRender& render);

	virtual void updateEvent(const BEvent& event);
	virtual void styleEvent(const BEvent& event);
	virtual void freshEvent(const BEvent& event);

	virtual void keyPressEvent(const BKeyEvent& keyEvent);
	virtual void keyReleaseEvent(const BKeyEvent& keyEvent);

	virtual void mouseEnterEvent(const BMouseEvent& mouseEvent);
	virtual void mouseLeaveEvent(const BMouseEvent& mouseEvent);
	virtual void mousePressEvent(const BMouseEvent& mouseEvent);
	virtual void mouseReleaseEvent(const BMouseEvent& mouseEvent);
	virtual void mouseMoveEvent(const BMouseEvent& mouseEvent);

	virtual void mouseClickEvent(const BMouseEvent& mouseEvent);

private:
	BHolder<DrawLineStripeNote>		_drawNote;
	BHolder<PrimitiveTransformer>	_transformer;
	BHolder<AdsorbVertexPicker>		_vertexPicker;
	BHolder<EdgePicker>				_edgePicker;
	BHolder<LineStripe>				_stripeShape;
	BHolder<BImage>					_dragImage;
	BVectorArray			_linePoints;
	bool					_lineChanged;
	bool					_dragging;
	Primitive				_hoveredPrimitive;
	int						_hoveredIndex;
	Primitive				_selectedPrimitive;
	BIntArray				_selectedIndices;
	BHolder<BPickHit>		_hoveredHit;
	BHolder<BPickHit>		_selectedHit;
};

#endif
